#include "StdAfx.h"
#include "SgQuad.h"
#include "graphics/GrVector.h"

CSgQuad::CSgQuad()
{
	m_normal[0] = 0.0;
	m_normal[1] = 1.0;
	m_normal[2] = 0.0;
}

CSgQuad::~CSgQuad(void)
{
}

void CSgQuad::SetProperties(GLdouble *v1, GLdouble *v2, GLdouble *v3, GLdouble *v4)
{
	m_V1[0] = v1[0];
	m_V1[1] = v1[1];
	m_V1[2] = v1[2];

	m_V2[0] = v2[0];
	m_V2[1] = v2[1];
	m_V2[2] = v2[2];

	m_V3[0] = v3[0];
	m_V3[1] = v3[1];
	m_V3[2] = v3[2];

	m_V4[0] = v4[0];
	m_V4[1] = v4[1];
	m_V4[2] = v4[2];
}

void CSgQuad::SetNormal(GLdouble *n)
{
	m_normal[0] = n[0];
	m_normal[1] = n[1];
	m_normal[2] = n[2];
}

void CSgQuad::SetTex( std::vector< std::vector<GLfloat> >  texCoords)
{
	m_texCoords = texCoords;
}

void CSgQuad::Render(void){

	glPushMatrix();
	glBegin(GL_QUADS);
		glNormal3dv(m_normal);
		if( m_texCoords.size() > 0)
			glTexCoord2f(m_texCoords[0][0], m_texCoords[0][1]);
		glVertex3dv(m_V1);
		if( m_texCoords.size() > 0)
			glTexCoord2f(m_texCoords[1][0], m_texCoords[1][1]);
		glVertex3dv(m_V2);
		if( m_texCoords.size() > 0)
			glTexCoord2f(m_texCoords[2][0], m_texCoords[2][1]);
		glVertex3dv(m_V3);
		if( m_texCoords.size() > 0)
			glTexCoord2f(m_texCoords[3][0], m_texCoords[3][1]);
		glVertex3dv(m_V4);
    glEnd();
	glPopMatrix();
}

